package com.xcity.pomelo.push.msg;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.xcity.game.buff.Buff;
import com.xcity.game.buff.BuffTemplate;
import com.xcity.pomelo.PomeloRoute;
import com.xcity.pomelo.push.AbstractMessagePush;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.PUSH, route = PomeloRoute.PUSH_MESSAGE)
public class BuffsPush extends AbstractMessagePush {

	private List<BuffInfo> buffs;
	
	public static class BuffInfo {
		private int id;
		private String name;
		private String desc;
		private String icon;
		private long createTime;
		private int durationTime;
		public BuffInfo() {}
		public BuffInfo(Buff buff) {
			this.id = buff.getId();
			this.name = buff.getTemplate().getName();
			this.desc = buff.getTemplate().getDesc();
			this.icon = buff.getTemplate().getIcon();
			this.createTime = buff.getCreateTime();
			this.durationTime = buff.getDuration() * 1000;
		}
		public int getId() {
			return id;
		}
		public void setId(int id) {
			this.id = id;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getDesc() {
			return desc;
		}
		public void setDesc(String desc) {
			this.desc = desc;
		}
		public String getIcon() {
			return icon;
		}
		public void setIcon(String icon) {
			this.icon = icon;
		}
		public long getCreateTime() {
			return createTime;
		}
		public void setCreateTime(long createTime) {
			this.createTime = createTime;
		}
		public int getDurationTime() {
			return durationTime;
		}
		public void setDurationTime(int durationTime) {
			this.durationTime = durationTime;
		}
	}
	
	public BuffsPush(List<Buff> buffs) {
		super(MSG_BUFFS);
		if (buffs == null || buffs.isEmpty()) {
			this.buffs = Collections.emptyList();
		} else {
			this.buffs = new ArrayList<BuffInfo>(buffs.size());
			for (int i = 0; i < buffs.size(); i++) {
				Buff buff = buffs.get(i);
				BuffTemplate temp = buff.getTemplate();
				BuffInfo info = new BuffInfo();
				this.buffs.add(info);
				info.id = buff.getId();
				info.name = temp.getName();
				info.desc = temp.getDesc();
				info.icon = temp.getIcon();
				info.createTime = buff.getCreateTime();
				info.durationTime = temp.getDuration() * 1000;
			}
		}
	}

	public List<BuffInfo> getBuffs() {
		return buffs;
	}

	public void setBuffs(List<BuffInfo> buffs) {
		this.buffs = buffs;
	}
	
}
